module(..., package.seeall)
--- 模块功能：门铃控制逻辑
-- @author zhangfenghe
-- @module access_control_system.doorbell_control_logic
-- @license MIT
-- @copyright openLuat
-- @release 2024.02.26
require "mqtt"
require "misc"
require "nvm"
require "config"
require "mqttHostOutMsg"
-- 初始化配置文件
nvm.init("config.lua", true)
-- 获取配置文件信息
local slaveNo, hostNo = nvm.get("ClientNo"), nvm.get("HostNo")
local topic, sendMsg = "", ""
local function gpio27IntFnc(msg)
    log.info("testGpioSingle.gpio27IntFnc", msg, GetGpio27Fnc())
    if msg == cpu.INT_GPIO_NEGEDGE then
        log.info(
            ">>>>>>>>>>>下降沿门铃动作出发，门铃逻辑开始！！<<<<<<<<<<<<<<<<<")
        -- 向主机发送门铃动作信息
        topic = "acs/" .. hostNo
        sendMsg = "{\"action\":\"bell\",\"slaveNo\":\"" .. slaveNo .. "\"}"
        mqttHostOutMsg.InsertHostMsg(topic, sendMsg, 0)
    end
end

-- 下降沿中断时：msg为cpu.INT_GPIO_POSEDGE；下降沿中断时：msg为cpu.INT_GPIO_NEGEDGE
GetGpio27Fnc = pins.setup(pio.P0_27, gpio27IntFnc)
